<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "dictionary";


// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("连接失败: " . $conn->connect_error);
}

// 获取小程序端的成语
$word = $_GET['word'];

// SQL语句
// 注意要 '" . $word . "' ，不能直接写$word会被整体当成字符串"$word"
$sql = "SELECT * FROM cy where name like '" . $word . "' LIMIT 1 ";
$result = $conn->query($sql);

// 如果查到有数据
if ($result->num_rows > 0) {
  // 输出数据
  while ($row = $result->fetch_assoc()) {
    $msg['result'] = $row;
    $msg['code'] = 1;
  }
} else {
  $msg['result'] = "没查到";
  $msg['code'] = 0;
}

// 关闭数据库
$conn->close();

//将编码编成json格式 
echo json_encode($msg);
